package controllers;

import java.net.UnknownHostException;

import jcifs.UniAddress;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbException;
import jcifs.smb.SmbSession;


public class WindowsDomainAuth {

  public static NtlmPasswordAuthentication authenticate( String domain, String username, String password ) {
    jcifs.Config.setProperty( "jcifs.netbios.wins", "10.144.11.221" );
    UniAddress dc;
    try {
      dc = UniAddress.getByName( "10.107.100.162" );
      NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication( domain, username, password );
      SmbSession.logon( dc, auth );
      return auth;
    }
    catch ( UnknownHostException e ) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return null;
    }
    catch ( SmbException e ) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      return null;
    }
  }
}
